<?php if(isset($notification)):?>
<b><?=$notification?></b>
<?php else:?>

<script type="text/javascript">

    window.addEvent('domready', function() {
        
    	$('edite_page').addEvent('submit', function(e) {
    		
            e.stop();
            $('ajax-loader').removeClass('hide');
            
            this.set('send', {
            	url : '<?=current_url()?>',
                onComplete: function(response) {

            	    if (response.test('<b><?=lang('create_page_success')?></b>')) {

            	    	ModalBoxClose();
            	    }
            	    else {

            	    	$('form_error').set('html', response);
            	    }
                    
                    ajax_url('<?=modul_url('', true)?>', 'main_content');
                }
            });
            
            this.send();
        });
        
    	$('get_method').addEvent('change', function(e) {

    		e.stop();
    		ajax_post('<?=modul_url("load_methods", true);?>', 'drop_method', {id:this.value});
    	});

    	$('get_templates_files').addEvent('change', function(e) {

            e.stop();
            ajax_post('<?=modul_url("load_templates", true);?>', 'drop_template', {id:this.value});
        });

    	//Tabs
        new SimpleTabs($('tab'), {
            selector: 'h4',
            onSelect: function(toggle, container, index) {

                toggle.addClass('tab-selected');
                container.setStyle('display', '');

                if (index == 1) {
                    
                    var mod = $('get_method').get('value');
                    var meth = $('drop_method').getElement('select').get('value');
                    
                    ajax_post('<?=modul_url("params_page", true);?>', container, {modul: mod, method: meth});
                }
            }
        });
    });
</script>

<?=form_open(current_url(), array('class' => 'hform', 'id' => 'edite_page'), array('add' => true));?>

<span id="form_error"></span>

<div id="tab">
    <h4>Основные</h4>
    <div>
        <p>
            <label><?=lang('tree_parent_id')?></label>
            <?=form_dropdown('parent_id', $pages, set_value('parent_id', '1'))?>
        </p>
        <p>
            <label><?=lang('tree_uri')?></label>
            <?=form_input('uri', set_value('uri'))?>
        </p>
        <p>
        	<label><?=lang('tree_title')?></label>
        	<?=form_input('title', set_value('title'))?>
        </p>
        <p>
        	<label><?=lang('tree_modul')?></label>
        	<?=form_dropdown('modul', $modules, set_value('modul'), 'id="get_method"')?>
        </p>
        <p>
        	<label><?=lang('tree_method')?></label>
        	<span id="drop_method"><?=form_dropdown('method', $methods, set_value('method'))?></span>
        </p>
        <p>
            <label><?=lang('tree_global_template')?></label>
            <?=form_dropdown('global_template', $templates, set_value('global_template'), 'id="get_templates_files"')?>
        </p>
        <p>
        	<label><?=lang('tree_template')?></label>
        	<span id="drop_template"><?=form_dropdown('template', $templates_files, set_value('template'))?></span>
        </p>
    </div>
    
    <h4>Параметры</h4>
    <div>
           
    </div>
    
    <h4><?=lang('rights_title')?></h4>
    <div>
        <table>
                <tr>
                    <th style="text-align: left; padding-left: 5px;"><?=lang('rights_groups')?></th>
                    <th style="text-align: center;"><?=lang('rights_view')?></th>
                    <th style="text-align: center;"><?=lang('rights_write')?></th>
                    <th style="text-align: center;"><?=lang('rights_admin')?></th>
                </tr>
        <?php foreach($groups as $row):?>
            <tr>
                <td style="text-align: left; padding-left: 5px;"><?=$row['title']?></td>
                <td style="text-align: center;"><?=form_checkbox('rights['.$row['id'].'][is_view]', 1, true);?></td>
                <td style="text-align: center;"><?=form_checkbox('rights['.$row['id'].'][is_write]', 1);?></td>
                <td style="text-align: center;"><?=form_checkbox('rights['.$row['id'].'][is_admin]', 1);?></td>
            </tr>
        <?php endforeach;?>
        </table>
    </div>
    
    <h4>Метаинформация</h4>
    <div>
        <p>
            <label><?=lang('tree_description')?></label>
            <?=form_textarea('description', set_value('description'),  ' style = "width: 430px; height: 100px;"')?>
        </p>
        <p>
            <label><?=lang('tree_keywords')?></label>
            <?=form_textarea('keywords', set_value('keywords'), ' style = "width: 430px; height: 100px;"')?>
        </p>
    </div>
    
    <h4>Прочие</h4>
    <div>
        <p>
            <label><?=lang('tree_mask')?></label>
            <?=form_input('mask', set_value('mask'))?>
        </p>
        <p>
            <label><?=lang('tree_parametrs')?></label>
            <?=form_input('parametrs', set_value('parametrs'))?>
        </p>
    </div>
</div>

<?=form_submit('add', lang('create'));?> <?=form_reset('reset', lang('reset'));?>

</form>
<?php endif;?>